import Taro from "@tarojs/taro";
import { checkTokenAuth } from "./util";
let isLoading = false;
let timer = null;
const navigateTo = Taro.navigateTo;

Taro.navigateTo = async arg => {
  /**解决暴力点击转转页面的问题 */
  if (isLoading) return;
  isLoading = true;
  const complete = arg.complete;
  arg.complete = function(result) {
    complete && complete(result);
    timer = setTimeout(() => {
      isLoading = false;
      timer = null;
    }, 100);
  };

  /**避免重复跳转一个页面 */
  const pages = Taro.getCurrentPages();
  const [lastPage] = pages.slice(-1);
  let [targetPage] = arg.url.split("?");
  targetPage = targetPage.slice(1);
  console.log(targetPage, "targetPage");
  if (lastPage?.route === targetPage && !arg.canRepeat)
    return (isLoading = false);
  navigateTo(arg);
};
